/**
 * 
 */
package com.wolfpire.proms.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.wolfpire.system.common.Constants;
import com.wolfpire.system.common.UnCover;

/**
 * 项目库指标
 * @author lihd
 *
 */

@Entity
@Table(name = "t_project_index")
public class ProjectIndex implements Serializable {
	
	private static final long serialVersionUID = -8150474095413624067L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", unique = true, nullable = false, length = 16)
	private Long id;//主键Id
	
	@Column(name = "name", length = 255)
	private String name; // 名称
	
	@Column(name = "code", length = 30)
	private String code; //编码
	
	@Column(name = "parent_id", length = 32)
	private Long parentId; //父级指标Id
	
	@Column(name = "seq", length = 3)
	private Integer seq; //排序
	
	@Column(name = "leaf")
	private boolean leaf = true; // 是否是叶子节点 true 是, flase 否
	
	@Column(name = "remark", length = 255)
	private String remark; // 描述
	
	@Column(name = "requirement", length = 255)
	private String requirement; // 要求
	
	@Column(name = "del_flag", length = 1)
	private Integer delFlag = Constants.NORMAL_FLAG; //伪删标识
	
	@Column(name = "create_user_id", length = 32)
	private Long crateUserId; //创建者
	
	@UnCover
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time")
	@DateTimeFormat(pattern="yyyy-MM-dd")  
	@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8") 
	private Date createTime = new Date();//创建时间[注册时间]
	
	@Column(name = "update_user_id", length = 32)
	private Long updateUserId;
	
	@Column(name = "weight")
	private String weight;//权重
	
	@Column(name = "plan_amount", length = 20)
	private String planAmount;// 计划使用资金
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "update_time")
	@DateTimeFormat(pattern="yyyy-MM-dd")  
	@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8") 
	private Date updateTime = new Date();//创建时间[注册时间]
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "end_time")
	@DateTimeFormat(pattern="yyyy-MM-dd")  
	@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8") 
	private Date endTime  = new Date();//计划结束时间
	
	@Transient
	private String state;
	
	@Transient
	private Long _parentId;
	
	@Transient
	private String text;
	
	@Transient
	private Long[] roleIds; // 角色Id集合
	
	@Transient
	private String roleIdsStr; // 角色Id串
	
	@Column(name = "expect_result", length = 255)
	private String expectResult;
	
	@Column(name = "path", length = 4000)
	private String path;
	
	@Column(name = "actor_id", length = 32)
	private Long actorId; //责任人
	
	@Column(name = "actor_name", length = 64)
	private String actorName; //责任人
	
	@Column(name = "path_id", length = 4000)
	private String pathId;
	
	@Transient
	private Long[] attaFunds; //资金类佐证材料
	
	@Transient
	private Long[] attaResult; //成果类佐证材料
	
	@Transient
	private Long[] attaAcceptance; //验收材料

	public ProjectIndex() {
		super();
	}

	public ProjectIndex(Long id, String name, String code, Long parentId,
			Integer seq, boolean leaf, String remark, String requirement,
			Integer delFlag, Long crateUserId, Date createTime,
			Long updateUserId, Date updateTime,String expectResult) {
		super();
		this.id = id;
		this.name = name;
		this.code = code;
		this.parentId = parentId;
		this.seq = seq;
		this.leaf = leaf;
		this.remark = remark;
		this.requirement = requirement;
		this.delFlag = delFlag;
		this.crateUserId = crateUserId;
		this.createTime = createTime;
		this.updateUserId = updateUserId;
		this.updateTime = updateTime;
		this.expectResult = expectResult;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRequirement() {
		return requirement;
	}

	public void setRequirement(String requirement) {
		this.requirement = requirement;
	}

	public Integer getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(Integer delFlag) {
		this.delFlag = delFlag;
	}

	public Long getCrateUserId() {
		return crateUserId;
	}

	public void setCrateUserId(Long crateUserId) {
		this.crateUserId = crateUserId;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Long getUpdateUserId() {
		return updateUserId;
	}

	public void setUpdateUserId(Long updateUserId) {
		this.updateUserId = updateUserId;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public boolean isLeaf() {
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}

	public String getState() {
		state = (this.leaf ? "open" : "closed");
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public Long get_parentId() {
		_parentId = this.parentId;
		return _parentId;
	}

	public void set_parentId(Long _parentId) {
		this._parentId = _parentId;
	}

	public String getText() {
		text = this.name;
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
	
	public Long[] getRoleIds() {
		return roleIds;
	}

	public void setRoleIds(Long[] roleIds) {
		this.roleIds = roleIds;
	}

	public String getRoleIdsStr() {
		if (!ArrayUtils.isEmpty(this.roleIds)) {
			return StringUtils.join(this.roleIds, ",");
		}
		return roleIdsStr;
	}

	public void setRoleIdsStr(String roleIdsStr) {
		/*if (!ArrayUtils.isEmpty(this.roleIds)) {
			this.roleIdsStr = StringUtils.join(this.roleIds, ",");
		}*/
		this.roleIdsStr = roleIdsStr;
	}

	public String getWeight() {
		return weight;
	}

	public void setWeight(String weight) {
		this.weight = weight;
	}

	public String getPlanAmount() {
		return planAmount;
	}

	public void setPlanAmount(String planAmount) {
		this.planAmount = planAmount;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getExpectResult() {
		return expectResult;
	}

	public void setExpectResult(String expectResult) {
		this.expectResult = expectResult;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Long getActorId() {
		return actorId;
	}

	public void setActorId(Long actorId) {
		this.actorId = actorId;
	}

	public String getActorName() {
		return actorName;
	}

	public void setActorName(String actorName) {
		this.actorName = actorName;
	}

	public String getPathId() {
		return pathId;
	}

	public void setPathId(String pathId) {
		this.pathId = pathId;
	}

	public Long[] getAttaFunds() {
		return attaFunds;
	}

	public void setAttaFunds(Long[] attaFunds) {
		this.attaFunds = attaFunds;
	}

	public Long[] getAttaResult() {
		return attaResult;
	}

	public void setAttaResult(Long[] attaResult) {
		this.attaResult = attaResult;
	}

	public Long[] getAttaAcceptance() {
		return attaAcceptance;
	}

	public void setAttaAcceptance(Long[] attaAcceptance) {
		this.attaAcceptance = attaAcceptance;
	}

}
